[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 creatnew()              Create a New File

 #include   <io.h>

 int        creatnew(filename,attrib);
 const char *filename;                   Name of new file
 int        attrib;                      Attribute word

    creatnew() creates a new file specified by 'filename'. It is
    identical to _creat() except that if the file exists, it returns an
    error and does nothing to this file.

    Like _creat(), creatnew() accepts the MS-DOS attribute word 'attrib',
    which must be one of the following constants (defined in <dos.h>):

                FA_RDONLY     Read only attribute
                FA_HIDDEN     Hidden file
                FA_SYSTEM     System file

       Returns:     If successful, returns the new file handle, a non-
                    negative integer.  On error, -1 is returned and
                    'errno' (defined in <errno.h>) is set to one of the
                    following:

                    ENOENT         Path or file name not found
                    EMFILE         Too many open files
                    EACCES         Permission denied
   Portability:     MS-DOS 3.0 and later only.

   -------------------------------- Example ---------------------------------

    The following statements create a new read-only file.

           #include <stdio.h>      /* for printf */
           #include <dos.h>         /* for _osmajor, FA_RDONLY */
           #include <io.h>         /* for creatnew */

           main()
           {
               int handle;

               if (_osmajor < 3)
                   printf("creatnew() only works for DOS 3.0 or later");
               else {
                   if ((handle = creatnew("newfile",FA_RDONLY)) == -1)
                       printf("couldn't create NEWFILE");
                   else
                       printf("NEWFILE created");
               }
           }

See Also: close() creat() _creat() creattemp()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson